// Copyright 2019 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include "video_core/renderer_opengl/gl_vars.h"

namespace OpenGL {
bool GLES;

//region 修改
inline u32 BGRA8888ToRGBA8888(u32 src) {
    u32 b = src & 0xFF;
    u32 g = (src >> 8) & 0xFF;
    u32 r = (src >> 16) & 0xFF;
    u32 a = (src >> 24) & 0xFF;
    return (a << 24) | (b << 16) | (g << 8) | r;
}

void FlipPixels(u32* pixels, u32 width, u32 height) {
    for (u32 y = 0; y < height; ++y) {
        for (u32 x = 0; x < width; ++x) {
            u32 from = width * y + x;
            u32 to = width * (height - y - 1) + x;
            if (from == to) {
                u32 from_value = BGRA8888ToRGBA8888(pixels[from]);
                pixels[from] = from_value;
                return;
            } else if (from < to) {
                u32 from_value = BGRA8888ToRGBA8888(pixels[from]);
                u32 to_value = BGRA8888ToRGBA8888(pixels[to]);
                pixels[from] = to_value;
                pixels[to] = from_value;
            } else {
                return;
            }
        }
    }
}
//endregion
}
